<#include "/lib/lib.html">
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>修改课程</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="${request.contextPath}/hplus/favicon.ico">
    <link href="${request.contextPath}/hplus/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${request.contextPath}/hplus/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="${request.contextPath}/hplus/css/animate.min.css" rel="stylesheet">
    <link href="${request.contextPath}/hplus/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="${request.contextPath}/hplus/css/plugins/bootstrap-table/bootstrap-table.min.css"  rel="stylesheet" >
    <link href="${request.contextPath}/hplus/css/plugins/bootstrap-validator/bootstrapValidator.min.css" rel="stylesheet">
    <link href="${request.contextPath}/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link rel="stylesheet" href="${request.contextPath}/hplus/css/plugins/bootstrap-fileinput/fileinput.min.css">
    <style>
        .form-control:focus,
        .single-line:focus {
            border-color: #0e9aef !important;
        }
    </style>
</head>
<body class="gray-bg">

<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins ibox-blue">
        <div class="ibox-title">
            <h5>修改课程</h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
                <a class="close-link">
                    <i class="fa fa-times"></i>
                </a>
            </div>
        </div>
        <div class="ibox-content">

            <div class="row row-lg">
                <form id="addFrom" class="form-horizontal" autocomplete="off">
                    <input type="hidden" name="id" value="${course.id!}">
                    <div class="form-group">
                        <label for="firstname" class="col-sm-2 control-label">课程名称</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="cname" value="${course.cname!}" placeholder="请输入课程名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="firstname" class="col-sm-2 control-label">课程描述</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="cname" value="${course.description!}" placeholder="请输入课程描述">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="firstname" class="col-sm-2 control-label">课程封面</label>
                        <div class="col-sm-10">
                            <input id="img" type="file" name="file">
                            <input type="hidden" name="img" value="${course.img!}">
                        </div>
                    </div>
                    <div class="controller" style="padding: 0 100px;">
                        <button type="submit" class="btn btn-primary btn-block">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script src="${request.contextPath}/hplus/js/jquery.min.js?v=2.1.4"></script>
<script src="${request.contextPath}/hplus/js/bootstrap.min.js?v=3.3.6"></script>
<!-- layer javascript -->
<script src="${request.contextPath}/hplus/js/plugins/layer/layer.min.js"></script>
<!-- 自定义js -->
<script src="${request.contextPath}/hplus/js/content.js?v=1.0.0"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.11.1/bootstrap-table.min.js"></script>
<!-- Latest compiled and minified Locales -->
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.11.1/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="${request.contextPath}/hplus/js/plugins/bootstrap-validator/bootstrapValidator.js"></script>
<script src="${request.contextPath}/hplus/js/plugins/iCheck/icheck.min.js"></script>
<script src="${request.contextPath}/hplus/js/plugins/bootstrap-fileinput/fileinput.min.js"></script>
<script src="${request.contextPath}/hplus/js/plugins/bootstrap-fileinput/locales/zh.js"></script>
<script>
    $("#img").fileinput({
        language: "zh",
        uploadUrl: '/upload',
        browseLabel: "上传预览图片",
        browseIcon: "<i class=\"glyphicon glyphicon-picture\"></i> ",
        allowedFileExtensions: ['jpg', 'gif', 'png'],
        showUpload: false,
        dropZoneEnabled: true,
        showPreview: true,
        minFileCount: 1,
        initialPreviewAsData: true,
        initialPreview: [
            "${course.img!}"
        ],
        initialPreviewConfig: [
            {caption: "${course.img!}", size: 329892, width: "120px", url: "${course.img!}", key: 1}
        ]
    }).on("filebatchselected", function(event, files) {
        $(this).fileinput("upload");
    }).on("fileuploaded", function(event, data, previewId, index) {
        var response = data.response;
        if (response.status) {
            $(".file-caption-name:last").text(data.response.filePath);
            $("input[name='img']").val(response.filePath);
        } else {
            parent.layer.msg(data.response.msg, {time: 1500, icon:5});
        }
    });

    $("#addFrom").submit(function (e) {
        e.preventDefault();
        var cname = $("input[name='cname']").val();
        if (cname == null || cname == "") {
            parent.layer.msg("请输入课程名称", {time: 1500, icon:5});
            return;
        }
        $.ajax({
            url: "/admin/course/updateCourse",
            data:  $("#addFrom").serialize(),
            type: "POST",
            dataType: 'json',
            success: function(data){
                if (data.success) {
                    parent.layer.msg(data.msg, {icon: 1});
                    window.location.href="/admin/course/list";
                }
            }
        });
    });
</script>
</body>
</html>